<template>
  <div>
    <!-- Navbar导航栏 -->
    <!-- <van-nav-bar
      title="黑马程序员.vant"
      left-text="返回"
      @click-left="onClickLeft"
      left-arrow
    /> -->
    <!-- 添加商品 -->
    <van-cell-group>
      <van-field v-model="value" placeholder="请输入商品名称" />
    </van-cell-group>
    <van-button type="info" @click="addGood">添加商品</van-button>
  </div>
</template>

<script>
import { Notify } from 'vant'
export default {
  name: 'addGood',
  data () {
    return {
      value: ''
    }
  },
  methods: {
    // 点击返回
    onClickLeft () {
      this.$router.go(-1)
    },
    // 点击按钮，添加商品
    async addGood () {
      if (this.value !== '') {
        const { data: res } = await this.$http.post('/api/addproduct', {
          params: this.value
        })
        if (res.status !== 0) {
          return Notify('添加商品失败！')
        }
        Notify('添加商品成功！')
      }
    }
  }
}
</script>

<style lang="less" scoped>
.van-button {
  width: 100%;
  margin-top: 30px;
}
</style>
